package com.lht.leetcodeDemo;

import org.junit.Test;

/**
 * @author Eric
 * @version 1.0
 * @date 2019-05-27
 */
public class ReverseBits {

    @Test
    public void test() {
        System.out.println(0B10111111111111111111111111111111);
        System.out.println(new ReverseBits().reverseBits(-3));
    }

    // you need treat n as an unsigned value
    public int reverseBits(int n) {
        int sum = 0;
        for (int i = 31; i >= 0; i--) {
            sum = (sum << 1) | (n & 0x1);
            n = n >> 1;
        }
        return sum;
    }
}
